package com.jit.app.adapter;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.jit.app.frament.CommentFragment;
import com.jit.app.frament.CreditFragment;
import com.jit.app.frament.DetailFragment;

public class AppDetailPagerAdapter extends FragmentPagerAdapter {

    String[] tabTitles = {"详情","评价","推荐"};
    Fragment[] fragments = new Fragment[tabTitles.length];

    public AppDetailPagerAdapter(FragmentManager fragmentManager){
        super(fragmentManager);
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        if (fragments[position] == null){
            switch (position){
                case 0:
                    fragments[position] = new DetailFragment();
                    break;
                case 1:
                    fragments[position] = new CommentFragment();
                    break;
                case 2:
                    fragments[position] = new CreditFragment();
                    break;
            }
        }
        return fragments[position];
    }

    @Override
    public int getCount() {
        return tabTitles.length;
    }

    //这个方法的返回值就是tab的文字内容
    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return tabTitles[position];
    }
}

